﻿using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;

namespace System
{
  internal static class CaDatetimeExtensions
  {
    /// <summary>Value for lining method</summary>
    private const MethodImplOptions AggressiveInlining = (MethodImplOptions)256;

    // http://www.csharp-examples.net/string-format-datetime/
    // http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx
    private const string TIME_FORMAT = "HH:mm:ss.fff 'GMT'"; // Example: 09:50:43.341 GMT
    private const string DATE_FORMAT = "yyyy-MM-dd"; // Example: 2010-09-02 - Variant of UniversalSorta­bleDateTimePat­tern
    private const string DATETIME_FORMAT = "yyyy-MM-dd " + TIME_FORMAT; // Example: 2010-09-02 09:50:43.341 GMT - Variant of UniversalSorta­bleDateTimePat­tern

    [MethodImpl(AggressiveInlining)]
    public static string Format(this DateTime dt)
    {
      return dt.ToString(DATETIME_FORMAT, CultureInfo.InvariantCulture);
    }

    [MethodImpl(AggressiveInlining)]
    public static string FormatDate(this DateTime dt)
    {
      return dt.ToString(DATE_FORMAT, CultureInfo.InvariantCulture);
    }

    [MethodImpl(AggressiveInlining)]
    public static string FormatTime(this DateTime dt)
    {
      return dt.ToString(TIME_FORMAT, CultureInfo.InvariantCulture);
    }

    [MethodImpl(AggressiveInlining)]
    public static string FormatWith(this DateTime dt, string format)
    {
      return dt.ToString(format, CultureInfo.InvariantCulture);
    }
  }
}
